#include "vlterraincontextwidget.h"

VLTerrainContextWidget::VLTerrainContextWidget(QWidget *parent) :
    VLContextWidget(parent)
{
    layout = setupLayout();

    surfaceEq = createAndAddLineEdit(layout, tr("Surface:"));
    redEq = createAndAddLineEdit(layout, tr("Red:"));
    greenEq = createAndAddLineEdit(layout, tr("Green:"));
    blueEq = createAndAddLineEdit(layout, tr("Blue:"));

    minX = createAndAddSpinBox(layout, 0, WORLD_XSIZE);
    minY = createAndAddSpinBox(layout, 0, WORLD_YSIZE);
    minZ = createAndAddSpinBox(layout, 0, WORLD_ZSIZE);

    maxX = createAndAddSpinBox(layout, 0, WORLD_XSIZE);
    maxY = createAndAddSpinBox(layout, 0, WORLD_YSIZE);
    maxZ = createAndAddSpinBox(layout, 0, WORLD_ZSIZE);

    maxX->setValue(WORLD_XSIZE);
    maxY->setValue(WORLD_YSIZE);
    maxZ->setValue(WORLD_ZSIZE);

    generateBtn = createAndAddButton(layout, tr("Generate!"));
    connect(generateBtn, SIGNAL(clicked()), this, SLOT(generateTerrain()));
}

void VLTerrainContextWidget::generateTerrain() {
    emit terrainEquationChanged(surfaceEq->text(), redEq->text(), greenEq->text(), blueEq->text(), minX->value(), minY->value(), minZ->value(), maxX->value(), maxY->value(), maxZ->value());
}

QLineEdit * VLTerrainContextWidget::createAndAddLineEdit(QHBoxLayout *tlayout, QString text) {
    QLineEdit *le = new QLineEdit();
    QLabel *label = new QLabel(text);
    tlayout->addWidget(label);
    tlayout->addWidget(le);
    return le;
}

QPushButton * VLTerrainContextWidget::createAndAddButton(QHBoxLayout *tlayout, QString text) {
    QPushButton *btn = new QPushButton(text);
    tlayout->addWidget(btn);
    return btn;
}
